<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/7/7 0007
  Time: 下午 4:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<html>
<head>
    <title>Title</title>
    <script src="../../js/jquery-3.3.1.min.js" charset="utf-8"></script>
    <script src="../../js/cookie/jquery.cookie.js" charset="utf-8"></script>
    <script src="../../layui-v2.2.5/layui/layui.js" charset="utf-8"></script>
    <link rel="stylesheet" href="../../layui-v2.2.5/layui/css/layui.css" media="all">
    <style>
        .layui-form-switch{
            width: 80px;
        }
        .layui-form-switch em {
            right: 34px;
        }
        .layui-form-onswitch i{
            left: 70px;
        }
        .layui-table-cell {
            height: auto;
            line-height: 28px;
        }
    </style>
</head>
<body>
<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right;margin-right: 100px"  href="javascript:location.replace(location.href);"
   title="刷新"><i class="layui-icon" style="line-height:30px">ဂ</i></a>
<br><br><br>
<form class="layui-form" action="">
    <table lay-filter="parse-table-demo">
        <thead>
        <tr>
            <th lay-data="{field:'permissionName', width:300}">菜单名称</th>
            <th lay-data="{field:'state', width:300}">菜单状态</th>
            <th lay-data="{field:'id', minWidth: 300}">菜单id</th>
            <th lay-data="{field:'two', minWidth: 300}">2级菜单</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${oneList}" var="one">
            <tr>
                <td>${one.name}</td>
                <td>
                    <div class="layui-input-block">
                        <input type="checkbox"  name="close" id="${one.id}" value="${one.id}"
                            <c:if test="${fn:contains(userOneList,one.id)==true  ||   fn:contains(roleOneList,one.id)==true}">
                                checked="checked"</c:if>
                               lay-filter="switchK"  lay-skin="switch" lay-text="已授权|未授权"   >
                    </div>
                </td>
                <td>${one.id}</td>
                <td>
                    <button class="layui-btn" type="button" onclick="twoPermission('${one.id}')" >设置二级菜单</button>
                </td>
            </tr>
        </c:forEach>

        </tbody>
    </table>
</form>

<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['form','table'], function(){
        var table = layui.table;
        var form=layui.form;
        table.init('parse-table-demo', { //转化静态表格

        });

        //监听指定开关
        form.on('switch(switchK)', function(data){
            console.log(data);
           /* layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });*/
            console.log(this.checked);
            $.ajax({
                url:'/adminSystem/settingUserOrRolePerssion',
                type:'POST', //GET
                async:true,    //或false,是否异步
                data:{
                    id:'${id}',
                    type:'${type}',
                    permissinId:data.value,
                    state:this.checked
                },
                timeout:5000,    //超时时间
                dataType:'html',    //返回的数据格式：json/xml/html/script/jsonp/text
                beforeSend:function(xhr){
                    /*console.log(xhr)
                     console.log('发送前')*/
                },
                success:function(data){
                    if (data.code!='000000'){
                        layer.msg(data.msg);
                    }
                    //console.log(data)
                },
                error:function(xhr,textStatus){
                    console.log('错误')
                    console.log(xhr)
                    console.log(textStatus)
                },
                complete:function(){
                    //console.log('结束')
                }
            })





        });


    });


    function twoPermission(id) {
       //   /adminSystem/onePermission
        layer.open({
            title:'二级菜单',
            type: 2,
            content: '/adminSystem/twoPermission?onePermissionId='+id+"&id=${id}&type=${type}",
            offset: '20px',
            shade:true,
            shadeClose:true,
            area: ["90%", "90%"]
        });
    }


</script>


</body>
</html>
